'use strict';
app.controller('propertyCtrl',['$scope','utilService','propertyService','toaster','$modal',
    function($scope,utilService,propertyService,toaster,$modal){
    $scope.withdrawal={
        state:1,
        type:0
    };

    $scope.page={};
    $scope.page.currentPage=1;
    //分页
    $scope.replacePage = function () {
        $scope.currentPage= $scope.page.currentPage;
        $scope.pageChanged();
    };

    $scope.query=function(){
        utilService.queryForPagingList($scope,{
            url:$scope.app.domain+"withdrawal",
            params: $scope.withdrawal
        }).then(function(result){
        })
    };
    $scope.query();

    $scope.changeType=function(type){
        $scope.list=new Array();
        $scope.withdrawal.type=type;
        $scope.query();
    };

    $scope.agree=function(id,status){
        var param={
            id:id,
            status:status
        };
        if(status == 1){
            openModal("您确定同意提现吗？");
        }else if(status == 2){
            openModal("您确定转账完成了吗？");
        }


        function openModal(msg){
            utilService.modal($modal, $scope, {
                title:"温馨提示",
                controller:"agreeCtrl",
                message:msg,
                data:param
            });
        }
    };

}]);

app.controller('agreeCtrl',['$scope','utilService','propertyService','toaster','modalData','$modalInstance',
    function($scope,utilService,propertyService,toaster,modalData,$modalInstance){
    $scope.modal = modalData;
    $scope.withdrawal={
        id:modalData.data.id,
        status:modalData.data.status
    };
    if($scope.withdrawal.status == 2){
        $scope.withdrawal.confirmType = 0;
    }

    $scope.ok = function(){
        if(!$scope.isDelModal){
            return;
        }
        $scope.isDelModal = false;
        propertyService.change($scope).then(function(result){
            switch (result.status){
                case 200:
                    $modalInstance.dismiss('success');
                    toaster.pop('success', "提示", "操作成功");
                    $scope.isDelModal=true;
                    $scope.query();
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break;
            }
        });
    };
    //取消弹窗
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
}]);

app.controller('withdrawalFailCtrl',['$scope','$state','propertyService','toaster','$stateParams',
    function($scope,$state,propertyService,toaster,$stateParams){
    $scope.withdrawal={
        id:$stateParams.id,
        status:3
    };
    $scope.confirm = function(){
        propertyService.change($scope).then(function(result){
            switch (result.status){
                case 200:
                    toaster.pop('success', "提示", "操作成功");
                    $state.go('app.property');
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break;
            }
        });
    }

}]);